package com.xzx.mr.sort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author xinzhixuan
 * @version V1.0
 * @date 2019/7/21 13:08
 */
public class FlowSortMapper extends Mapper<LongWritable, Text, FlowBean, Text> {
    private FlowBean outputKey = new FlowBean();
    private Text outputValue = new Text();

    // 13470253144	180	180	360
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //一行一行的获取
        String line = value.toString();
        String[] fields = line.split("\t");
        String phoneNumber = fields[0];
        String upFlow = fields[1];
        String downFlow = fields[2];
        String sumFlow = fields[3];

        outputKey.setUpFlow(Long.parseLong(upFlow));
        outputKey.setDownFlow(Long.parseLong(downFlow));
        outputKey.setSumFlow(Long.parseLong(sumFlow));

        outputValue.set(phoneNumber);

        context.write(outputKey, outputValue);
    }
}
